{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "import pandas as pd\n",
    "from src import config, utils\n",
    "import logging\n",
    "import pickle"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {
    "collapsed": false,
    "scrolled": true
   },
   "outputs": [
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "WARNING:root:Will set task, dataset = test\n",
      "WARNING:root:Will select ['UserInfo_82', 'UserInfo_222', 'UserInfo_262', 'a_feature']\n"
     ]
    }
   ],
   "source": [
    "logging.warning('Will set task, dataset = test')\n",
    "config.task = 'test'\n",
    "config.dataset = 'test'\n",
    "\n",
    "test = pd.read_csv(config.pj_root + 'data/' + config.dataset + '.csv', index_col='no')\n",
    "a_feature = pd.read_csv(config.pj_root + 'data/a_feature_test.csv', index_col='no')\n",
    "test = test.join(a_feature)\n",
    "\n",
    "if len(config.drop_columns) != 0:\n",
    "    logging.warning('Will drop %s' % str(config.drop_columns))\n",
    "    test = test.drop(config.drop_columns, axis=1)\n",
    "\n",
    "if len(config.select_columns) != 0:\n",
    "    logging.warning('Will select %s' % str(config.select_columns))\n",
    "    test = test[config.select_columns]\n",
    "\n",
    "X = test.values[:, 0:]  # all columns\n",
    "\n",
    "with open(config.pj_root + 'model/%s.mo' % config.model.__name__, 'rb') as f:\n",
    "    model = pickle.load(f)\n",
    "pred = model.predict_proba(X)\n",
    "\n",
    "pred = pred[:, 1]\n",
    "pred_df = pd.DataFrame(index=test.index)\n",
    "pred_df = pred_df.join(pd.DataFrame(pred, index=test.index, columns=['pred']))\n",
    "pred_df.to_csv(config.pj_root + 'result/qianhai_%s.csv' % (config.model.__name__))\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([[-1.        , -1.        , -1.        , ..., -1.        ,\n",
       "        -1.        ,  0.38425183],\n",
       "       [-1.        , -1.        ,  0.        , ...,  0.        ,\n",
       "        -1.        ,  0.10878124],\n",
       "       [-1.        , -1.        ,  0.        , ...,  0.        ,\n",
       "        -1.        ,  0.20546034],\n",
       "       ..., \n",
       "       [-1.        , -1.        , -1.        , ..., -1.        ,\n",
       "        -1.        ,  0.08807795],\n",
       "       [-1.        , -1.        , -1.        , ..., -1.        ,\n",
       "        -1.        ,  0.12280237],\n",
       "       [-1.        , -1.        , -1.        , ..., -1.        ,\n",
       "        -1.        ,  0.18085909]])"
      ]
     },
     "execution_count": 5,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "X"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "anaconda-cloud": {},
  "kernelspec": {
   "display_name": "Python [conda root]",
   "language": "python",
   "name": "conda-root-py"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.5.2"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 1
}
